package com.itheima.day06_demo;

import java.util.Random;
import java.util.Scanner;

public class Demo2_verification_code {
    public static void main(String[] args) {
        //目标生成随机验证码
        Scanner scanner = new Scanner(System.in);

        while (true){
            System.out.println("请输入验证码的长度：");
            int n = scanner.nextInt();
            String code = getVerificationCode(n);
            System.out.println("验证码为：" + code);
        }
    }
    public static String getVerificationCode(int n) {
        Random r = new Random();

        String code = "";
        for (int i = 0; i < n; i++) {
            int type = r.nextInt(3);
            switch ( type){
                case 0:
                    code += (char)(r.nextInt(26) + 'a');
                    break;
                case 1:
                    code += (char)(r.nextInt(26) + 'A');
                    break;
                case 2:
                    code += r.nextInt(10);
                    break;
            }
        }
        return code;
    }

}
